#!/usr/bin/bash

WD=/path/to/virtualenv/more_power/more_power
cd /path/to/virtualenv/more_power
source bin/activate
PIDFILE=${WD}/morepowerdns.pid
PYTHON=`which python`
SOCKET=/tmp/morepowerdns.sock
export DJANGO_SETTINGS_MODULE=morepowerdns.settings

case "$1" in
        start)
                $PYTHON $WD/manage.py runfcgi socket=$SOCKET daemonize=true method=threaded protocol=fcgi pidfile=$PIDFILE
                sleep 3
                chmod a+rwx $SOCKET
                ;;

        stop)
                kill `cat $PIDFILE`
                ;;

        restart)
                $0 stop && $0 start
                ;;

        *)
                echo "Usage: $0 {start|stop|restart}"
                ;;
esac
exit 0
